SRC = .
MUDUO_PATH = ~/build/release-install-cpp11
UDNSDIR = $(SRC)/muduo-udns/udns-0.2
CXX = g++
CXXFLAGS = -std=c++14 -Wconversion -Wall -I $(MUDUO_PATH)/include
CXXDLAGS = -L $(MUDUO_PATH)/lib/ -L $(UDNSDIR)  -lmuduo_net -lmuduo_base -ludns -lpthread -lrt 

SOURCES    = $(wildcard *.cc)
OBJECTS    = main.o tunnel.o socks4a.o muduo-udns/Resolver.o
EXECUTABLE =  socks4a
INCLUDE    = -I $(MUDUO_PATH)/include
release: CXXFLAGS += -O3 -DNDEBUG
release: $(EXECUTABLE)      

muduo-udns/Resolver.o: muduo-udns/Resolver.cc muduo-udns/Resolver.h
	cd muduo-udns; make

debug: CXXFLAGS += -g3 -DDEBUG
debug:  
	$(CXX) $(INCLUDE) $(CXXFLAGS) $(OBJECTS)  $(CXXDLAGS) -o $(EXECUTABLE)_debug

all: release debug
$(EXECUTABLE): $(OBJECTS)
ifeq ($(EXECUTABLE), executable)
	@echo Edit EXECUTABLE variable in Makefile.
	@echo Using default a.out.
	$(CXX) $(INCLUDE) $(CXXFLAGS) $(OBJECTS)  $(CXXDLAGS) 
else
	$(CXX) $(INCLUDE) $(CXXFLAGS) $(OBJECTS)  $(CXXDLAGS) -o $(EXECUTABLE)
	cd ./socks4Nosync;make 
	cd ./single-threaded;make 
endif
	
.PHONY : clean 
clean : 
	-rm -f $(OBJECTS) $(EXECUTABLE) $(EXECUTABLE)_debug
	cd ./socks4Nosync;make clean
	cd ./single-threaded;make clean
	cd ./muduo-udns; make clean
